unit uDZCtrlUtils;

interface

uses
  ComCtrls;

procedure TreeView_CollapseExcept(node: TTreeNode);
procedure TreeView_CollapseAll(view: TTreeView);

implementation

procedure TreeView_CollapseExcept(node: TTreeNode);
var
  nodeSibling: TTreeNode;
begin
  nodeSibling := node.getPrevSibling;
  while (nodeSibling <> nil) do
  begin
    nodeSibling.Collapse(False);
    nodeSibling := nodeSibling.getPrevSibling;
  end;
  nodeSibling := node.getNextSibling;
  while (nodeSibling <> nil) do
  begin
    nodeSibling.Collapse(False);
    nodeSibling := nodeSibling.getNextSibling;
  end;
  if (node.Parent <> nil) then
    TreeView_CollapseExcept(node.Parent);
end;

procedure TreeView_CollapseAll(view: TTreeView);
var
  node: TTreeNode;  
begin
  node := view.Items.GetFirstNode;
  while node <> nil do
  begin
    if node.Expanded then node.Collapse(True);
    node := node.getNextSibling;
  end;
end;

end.
